package org.example.Demo01;

import org.example.Join.JDBC_Join;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;

public class JDBC_Delete {
    /*
    根据id进行删除元素
    * */
    private JDBC_Join jdbcJoin = new JDBC_Join();

    public int delete() throws Exception {

        Connection conn = jdbcJoin.join();

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要删除的id:");
        int id = sc.nextInt();

        String sql = "delete from tb_brand where id = ?";
        PreparedStatement prepstmt = conn.prepareStatement(sql);
        prepstmt.setInt(1,id);
        //count为受影响的行数
        int count = prepstmt.executeUpdate();
        return count;
    }
}
